from django.http import JsonResponse


def iflogin(func):
    def warpper(request,*args,**kwargs):
        if request.user.is_authenticated:
            func(request,*args,**kwargs)
            return func( request, *args, **kwargs )
        else:
            return JsonResponse( {'code': 400,
                                  'errmsg': '请先登录'} )
    return warpper

class IfloginMixin():
    @classmethod
    def as_view(cls,*args,**kwargs):
        view = super().as_view(*args,**kwargs)
        view = iflogin(view)
        return view
